#include <linux/sched.h>
#include <linux/sys.h>
#include <linux/segment.h>

struct timeval xtime; /* The current time */

int system_call(void);

static unsigned long init_kernel_stack[1024];
struct task_struct init_task = INIT_TASK;

struct task_struct *task[NR_TASKS] = {
    &init_task,
};

long user_stack[PAGE_SIZE >> 2];

struct {
    long *a;
    short b;
} stack_start = {&user_stack[PAGE_SIZE >> 2], KERNEL_DS};

fn_ptr sys_call_table[] = {0, 0, sys_fork};

int NR_syscalls = sizeof(sys_call_table) / sizeof(fn_ptr);

void sched_init(void) {
    int i;
    struct desc_struct *p;

    set_tss_desc(gdt + FIRST_TSS_ENTRY, &(init_task.tss));
    set_ldt_desc(gdt + FIRST_LDT_ENTRY, &(init_task.ldt));
    set_system_gate(0x80, &system_call);
    p = gdt + 2 + FIRST_TSS_ENTRY;
    for (i = 1; i < NR_TASKS; i++) {
        task[i] = NULL;
        p->a = p->b = 0;
        p++;
        p->a = p->b = 0;
        p++;
    }
    __asm__("pushfl\n\tandl $0xffffbfff, (%esp)\n\tpopfl");
    load_TR(0);
    load_ldt(0);
}
